package view;

import java.awt.event.ActionEvent;
import java.net.URL;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JMenuItem;

import accounts.Authorization;
import controller.ConnectionTester;

public class SimulationPanel extends MainPanel{
	private JMenuItem menuItem_Open, menuItem_Run, menuItem_Stop;
	private JMenuItem menuItem_EditMode, menuItem_SecurityMode;
	private JButton openBtn, runBtn, stopBtn, setSNBtn;
	
	public SimulationPanel(){
		super();
	}
	
	public void setupMenuBar(){
		if(authorization == Authorization.ADMINISTRATOR) {
			menuItem_EditMode = new JMenuItem();
			toolbar.setAction(menuItem_EditMode, "Edit Configuration Mode", null);
			menuMode.add(menuItem_EditMode);
			
			menuItem_SecurityMode = new JMenuItem();
			toolbar.setAction(menuItem_SecurityMode, "Security Mode", null);
			menuMode.add(menuItem_SecurityMode);
		}
		
		menuItem_Open = new JMenuItem();
		toolbar.setAction(menuItem_Open, "Open", null);
		menuFile.add(menuItem_Open);
		
		menuItem_Run = new JMenuItem();
		toolbar.setAction(menuItem_Run, "Run Simulation", null);
		menuEdit.add(menuItem_Run);
		
		menuItem_Stop = new JMenuItem();
		toolbar.setAction(menuItem_Stop, "Stop Simulation", null);
		//menuMode.add(menuItem_Stop);
		
	}
	
	public void setupToolbar(){
		openBtn = toolbar.makeButton("open", "Open");
		toolbar.add(openBtn);
		
		runBtn = toolbar.makeButton("run", "Run Simulation");
		toolbar.add(runBtn);
		
		stopBtn = toolbar.makeButton("stop", "Stop Simulation");
		stopBtn.setVisible(false);
		toolbar.add(stopBtn);
		
		toolbar.addSeparator();
		setSNBtn = toolbar.makeButton("node", "Click if current node is this machine");
		toolbar.add(setSNBtn);
		
		toolbar.addSeparator();
		toolbar.setupNodeGroupButtons();
		
	}
	
	public void setupCanvasPanel(){
		
	}
	
	public void setupAttributesPanel(){
		
	}
	
	public void playSelected(){
		runBtn.setVisible(false);
		stopBtn.setVisible(true);
		menuEdit.remove(menuItem_Run);
		menuEdit.add(menuItem_Stop);
		ConnectionTester.runSimulation();
	}
	
	public void stopSelected(){
		stopBtn.setVisible(false);
		runBtn.setVisible(true);
		menuEdit.add(menuItem_Run);
		menuEdit.remove(menuItem_Stop);
		ConnectionTester.stopSimulation();
	}
	
}
